using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Yozeev.Configuration;
using Yozeev.Helpers;

namespace Yozeev.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class YozeevDbContextFactory : IDesignTimeDbContextFactory<YozeevDbContext>
    {
        public YozeevDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<YozeevDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            YozeevDbContextConfigurer.Configure(builder,
                configuration.GetConnectionString(AppConsts.ConnectionStringName));

            return new YozeevDbContext(builder.Options);
        }
    }
}